﻿using System;
using System.IO.IsolatedStorage;

namespace Com.PhilChuang.Utils.Wp7
{
	// adapted from http://www.jaykimble.net/silverlightwp7-tip-detecting-when-in-vs-design-mode.aspx
	public static class DesignModeDetector
	{
		private static readonly Object lock_s_IsInDesignMode = new object ();
		private static bool? s_IsInDesignMode = null;

		public static bool IsInDesignMode // Convenient method that can be accessed out of an inherited class
		{
			get
			{
				if (s_IsInDesignMode != null)
					return s_IsInDesignMode.Value;

				lock (lock_s_IsInDesignMode)
				{
					if (s_IsInDesignMode != null)
						return s_IsInDesignMode.Value;
					try
					{
						var isoStor = IsolatedStorageSettings.ApplicationSettings.Contains ("nonsense_text_abcdef");
						s_IsInDesignMode = false;
					}
					catch (Exception)
					{
						// If we get here that means we got an error
						s_IsInDesignMode = true;
					}
				}
				return s_IsInDesignMode.Value;
			}
		}
	}
}